package westh.ilib.struts.action.manage.researcher;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONObject;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.mule.extras.client.MuleClient;
import org.mule.umo.UMOMessage;

import westh.config.Config;
import westh.ilib.struts.action.manage.researcher.ResearcherDelAction;
import westh.util.YyAction;

public class ResearcherDelAction extends YyAction{
	private static org.apache.commons.logging.Log log = org.apache.commons.logging.LogFactory.getLog(ResearcherDelAction.class);
	//get clouds Ip address
	String localhostUrl = Config.get("localhostUrl");
	String remoteUrl = Config.get("remoteUrl");

	  public ActionForward doAction(ActionMapping mapping,ActionForm form,HttpServletRequest request,HttpServletResponse response) {
//			日志和权限检查，请勿删除		 
		  westh.log.YyLog.addFootprint(request, "动作-删除资源信息");
		  String researcherId=request.getParameter("researcherId");
		  //数据文件
		  String dbName = "researcher.dbxml";
	 
		  JSONObject inJson= new JSONObject();//删除资源输入JSONObject
		  inJson.put("dbName", dbName);
		  inJson.put("resId", researcherId);	//researcher is a type of resource
		  String inputStr = inJson.toString();
		  //删除资源输出JSONObject
		  String outString="";
		  try {
			  MuleClient clientD = new MuleClient();
			  //调用WebService
			  UMOMessage umo = clientD.send("axis:http://"+localhostUrl+":4381/LIBJson/iDlibJson?method=delRes",inputStr,null);
			  outString = (String)umo.getPayload();
		  } catch (Exception e) {
			  throw new RuntimeException(e);
		  }
		  //解析outString
		  JSONObject researcherOutStr=JSONObject.fromObject(outString);
		  String retCode=researcherOutStr.getString("retCode");
		  if(retCode.equals("0100")){
			  request.setAttribute("info", "删除成功"); 
			  request.setAttribute("redirect", "../researcherListPre.do");
            return mapping.findForward("info");  
		  }else{
			  request.setAttribute("info", "删除失败"); 
			  request.setAttribute("redirect", "../researcherListPre.do");
            return mapping.findForward("info");  
		  }
	  }

}
